package leetcode;

import java.util.ArrayList;

/**
 * Created by Ghost on 2014/11/6 0006.
 */
public class Validate_Binary_Search_Tree {
    private ArrayList<Integer> list = new ArrayList<Integer>();

    public void preOrder(TreeNode root){
        if(root==null){
            return;
        }
        preOrder(root.left);
        list.add(root.val);
        preOrder(root.right);
    }

    public boolean isValidBST(TreeNode root) {
        if(root==null)
            return true;
        preOrder(root);
        int a = list.get(0)-1;
        for(Integer num:list){
            if(num>a){
                a = num;
            }
            else
                return false;
        }
        return true;
    }
    public static void main(String[] args){
        Validate_Binary_Search_Tree validate_binary_search_tree = new Validate_Binary_Search_Tree();
        TreeNode head = new TreeNode(8);
//        head.left = new TreeNode(3);
//        head.right = new TreeNode(14);
//        head.left.right = new TreeNode(8);
        System.out.println(validate_binary_search_tree.isValidBST(null));
    }
}
